﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MathLib;
using System.Windows.Forms.DataVisualization.Charting;

namespace Demog
{
    public partial class Graph : Form
    {
        private Matrix x;
        private Matrix y;
        private Matrix z;

        public Graph(Matrix x, Matrix y, Matrix z)
        {
            InitializeComponent();

            manChart.ChartAreas.Add("Man");
            womanChart.ChartAreas.Add("Woman");
            this.x = x;
            this.y = y;
            this.z = z;
        }

     private void DrawPrediction(int start, int finish, Matrix notFiltered, Matrix filtered, Matrix realdata, Chart chart) {
            Series notFilteredSer = chart.Series.Add("Прогноз без фильтра");
            Series filteredSer = chart.Series.Add("Прогноз с фильтром");
            Series realSer = chart.Series.Add("Реальные данные");
            notFilteredSer.ChartType = SeriesChartType.Column;
            filteredSer.ChartType = SeriesChartType.Column;
            int startAge = 0;
            const int step = 4;
            for (int i = start; i < finish; i++) {
                notFilteredSer.Points.AddXY(i, notFiltered[i, 0]);
                realSer.Points.AddXY(i, realdata[i, 0]);
                int pointIndex = filteredSer.Points.AddXY(i, filtered[i, 0]);
                filteredSer.Points[pointIndex].AxisLabel = startAge + " - " + (startAge + step);
                startAge += step + 1;
            }
        }

        private void chart1_Click(object sender, EventArgs e) {

        }

        private void Graph_Shown(object sender, EventArgs e) {
            int middle = x.NoRows / 2;
            // Мужчины
            DrawPrediction(0, middle, x, y, z, manChart);
            // Женщины
            DrawPrediction(middle, x.NoRows, x, y, z, womanChart);
        }
    }
}
